<?php
/**
 * @file $HeadURL: featurelibrarycontroller.php $
 * @author $Author: yuebin (yuebin@haibao.com) $
 * @date $Date: 2016年9月21日 11:48:35 $
 * @brief 专题库控件
 */
namespace haibao\cms\business\control\pc\channel\library;


class FeatureLibraryController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	private $dataList = array();
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	public function displayTemplateHtml(){
	    $controlData = $this->getParameter(self::$CONTROL_DATA);
	    $content = $this->getParameter(self::$CONTROL_CONTENT);
	    $path = $this->generateHtmlPath(__CLASS__);

		//$featureSerialList = \haibao\cms\business\control\FeatureController::$featureSerial;
		$featureSerialList = \haibao\cms\business\control\FeatureController::getFeatureSerialArray();
		$featureSerialImage = \haibao\cms\business\control\FeatureController::getImageUrlBySerials();
		foreach($featureSerialList as $key=>$val){
		    $temp[$key]['ChannelName'] = $val['SerialName'];
		    if(isset($val['children'])){
		        foreach($val['children'] as $k=>$v){
		            $temp[$key]['SerialIds'][$v['Id']]['SerialName'] = $v['SerialName'];
		            if($key !=3){
		                $temp[$key]['SerialIds'][$v['Id']]['SerialUrl'] = $v['SerialLogoUrl'];
		            }
		        
		        }
		    }
		}
		$featureSerialList = $temp;
		$finalFeatureArr = array();
		foreach($featureSerialList as $channelId=>$featureSerial){
			if($channelId == 3 || $featureSerial['ChannelName'] == '直播/策划'){
				foreach($featureSerial['SerialIds'] as $classId=>$info){
//					$finalFeatureArr[$channelId][$classId]['List'] = \haibao\cms\business\control\FeatureController::getNewFeatureByClassId($classId);
                    $finalFeatureArr[$channelId][$classId]['List'] = \haibao\cms\business\control\FeatureController::getNewFeatureBySerialId($classId);
				}
			}else{
				$finalFeatureArr[$channelId][0]['List'] = \haibao\cms\business\control\FeatureController::getNewFeatureBySerialId(array_keys($featureSerial['SerialIds']));
				$featureSerialArr = \haibao\cms\business\control\FeatureController::getSerialInfo(array_keys($featureSerial['SerialIds']));
				foreach($featureSerial['SerialIds'] as $serialId=>$info){
					$list = \haibao\cms\business\control\FeatureController::getNewFeatureBySerialId($serialId,5);
					if(count($list) < 5) $list = array_pad($list, 5, array('SerialImageUrl'=>(isset($featureSerialImage[$serialId]) && !empty($featureSerialImage[$serialId]['SerialLogoUrl']))?self::getImageLink($featureSerialImage[$serialId]['SerialLogoUrl'],300,300):""));
					
					$finalFeatureArr[$channelId][$serialId]['List'] = $list;
					$finalFeatureArr[$channelId][$serialId]['SerialName'] = (isset($featureSerialArr[$serialId]))?$featureSerialArr[$serialId]['SerialName']:'';
					$finalFeatureArr[$channelId][$serialId]['SerialDesc'] = (isset($featureSerialArr[$serialId]))?$featureSerialArr[$serialId]['SerialDesc']:'';
					$finalFeatureArr[$channelId][$serialId]['SerialImage'] = (isset($featureSerialArr[$serialId]))?$featureSerialArr[$serialId]['SerialLogoUrlBig']:'';
					if(!empty($list) && isset($list[0]['Id'])){
					    $featureSerialList[$channelId]['SerialIds'][$serialId]['IsEmpty'] = 1;
					    $finalFeatureArr[$channelId][$serialId]['IsEmpty'] = 1;
					}
					
				}
			}
		}
		$this->assign('finalFeatureArr',$finalFeatureArr);
		$this->assign('featureSerialList',$featureSerialList);
		$this->assign('exclusiveHost',\haibao\classlibrary\Config::getConfig(\haibao\classlibrary\Config::CLASSLIBRARY_CONFIG_HOST_EXCLUSIVE).'/featureflow/');
		$isNewHtml = $this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;

	}
	
}